<template>
    <rx-dialog @ok="handTrans" @cancel="cancel">
        <rx-layout>
            <template #middle>
                <div>
                    <a-form ref="form" :model="form" :rules="rules" class="rx-a-form-vertical" layout="vertical">
                        <span style="color: #4d9eff;font-size: 16px;margin-bottom: 10px;display: inline-block;">{{ form.subject }}</span>
                        <a-row>
                            <a-col :span="24">
                                <a-form-item :label="i18n('transferPage.transferor','转办人')" name="toUser">
                                    <rx-user-component v-model="form.toUser" :isAccount="false"
                                                       :single="true"></rx-user-component>
                                </a-form-item>
                            </a-col>
                        </a-row>
                        <a-row>
                            <a-col :span="24">
                                <a-form-item :label="i18n('taskCheck.opinion','意见')" name="opinion">
                                    <a-textarea v-model:value="form.opinion" style="width: 100%"/>
                                </a-form-item>
                            </a-col>
                        </a-row>
                    </a-form>
                </div>
            </template>
        </rx-layout>
    </rx-dialog>
</template>
<script>

import {BaseFormModel, RxDialog, Util} from '@lowcode/jpaas-base-lib';
import {RxUserComponent} from '@lowcode/jpaas-share-component';
import BpmtaskApi from "@/common/api/bpm/bpmTask";

export default {
    name: 'BpmTaskTransferEdit',
    props: {
        subject: String,
        taskId: String,
        layerid: String,
        destroy: Function
    },
    mixins: [BaseFormModel],
    components: {
        RxDialog, RxUserComponent
    },
    data() {
        return {
            rules: {
                toUser: [{
                    required: true,
                    message: this.i18n('transferPage.transferor', '转办人', 'select'),
                    trigger: 'change'
                }]
            },
            form: {
                opinion: "",
                toUser: [],
                msgTypes: []
            }
        }
    },
    created() {
        this.init();
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "bpmTask", key);
        },
        init() {
            this.form.subject = this.subject;
            this.form.taskId = this.taskId;
        },
        handTrans(e) {
            var self = this;
            this.$refs.form.validate().then(() => {
                self.form.msgType = self.form.msgTypes.join(",");
                self.$confirm({
                    title: self.i18n('transferPage.confirmTransfer', '确认转办任务吗?'),
                    okText: self.$ti18('rxForm.ackBtn', '确认'),
                    cancelText: self.$ti18('rxForm.cancelBtn', '取消'),
                    zIndex: 9999,
                    onOk() {
                        BpmtaskApi.transTask(self.form).then(res => {
                            e.loading = false;
                            Util.closeWindow(self, "ok")
                        })
                    },
                    onCancel() {
                        e.loading = false;
                    }
                });
            }).catch((error) => {
                e.loading = false;
            })
        }
    }
}
</script>
